<?php

namespace App\Console\Commands;

use App\Models\sf_order;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;

class OrderCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'OrderCommand';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $data=sf_order::where('order_status',0)->get()->toArray();
        foreach ($data as $v){
            if(time()-strtotime($v['created_at'])>=60*30){
                $res=sf_order::where('order_id',$v['order_id'])->update(['order_status'=>2]);
                $email='1764749557@qq.com';
                if($res){
                   Mail::raw('订单半小时内未支付,订单号为'.$data['order_sn'].'已取消',function ($query)use($email){
                       $query->Subject('订单取消通知')->to($email);
                   });
                }
            }
        }
    }
}
